package com.example.denglu.service.imp;

import com.alibaba.druid.sql.visitor.functions.If;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.example.denglu.dto.UserInformationExcelDto;
import com.example.denglu.entity.UserInformation;
import com.example.denglu.mapper.UserInformationMapper;
import com.example.denglu.service.UserInformationService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.Assert;

import java.util.List;

@Service
public class UserInformationServiceImp  extends ServiceImpl<UserInformationMapper,UserInformation> implements UserInformationService {
    @Autowired
    UserInformationMapper userInformationMapper;

    //插入信息
    public String add(UserInformation userInformation){
       UserInformation OK =  userInformationMapper.selectByName(userInformation.getName());
        try {
            if (OK!= null){
                return "信息录入失败，该信息已存在";
            }else {
                userInformationMapper.insertSelective(userInformation);
                return "信息录入成功";
            }
        } catch (Exception e) {
            e.printStackTrace();
           return e.getMessage();
        }

    }

    //根据姓名查找
    public UserInformation SelectByName(String name){
        UserInformation byName = userInformationMapper.selectByName(name);
         return byName;
    }

    //根据性别查找
    public List<UserInformation> SelectByGender(String gender){
        List<UserInformation> byGender = userInformationMapper.selectByGender(gender);
        return byGender;
    }

    //根据职位查找
    public  List<UserInformation> SelectByPosition(String position){
        List<UserInformation> byPosition = userInformationMapper.selectByPosition(position);
        return byPosition;
    }
    //删除信息
    public  String DeleteByName(String name){
         userInformationMapper.updateDeletedByName(1,name);
        UserInformation byName =   userInformationMapper.selectByName(name);
        try {
            if (byName.getDeleted() != 0){
                return "删除成功";
            }else {
                return "删除失败";
            }
        } catch (Exception e) {
            e.printStackTrace();
            return e.getMessage();
        }
    }

    //显示全部
    public  List<UserInformation> FindAll(){
        List<UserInformation> findAll = userInformationMapper.findAllByDeleted(0);
        return findAll;
    }

    public  List<UserInformationExcelDto> Download(){
        List<UserInformationExcelDto> download = userInformationMapper.Download(0);
        return download;
    }

    @Override
    public List<UserInformation> FindKeyWord(String keyWord) {
        userInformationMapper.findByKeyWord(keyWord);
        return null;
    }

}
